use "${clean_data}\gfs_cleaned_merged_database.dta", clear
cd "${output}\"

*****************
**reverse code **
****************
foreach  i in health_growup {
gen RE`i'=5 if `i'==1
replace RE`i'=4 if `i'==2
replace RE`i'=3 if `i'==3
replace RE`i'=2 if `i'==4
replace RE`i'=1 if `i'==5
}

***
***convergent, divergent, and content validity
****

gen unemployed=1 if employment==6
replace unemployed=0 if employment!=6 & employment<=7

*Convergent and divergent validity
pwcorr HOPE HAPPY ACCEPTED_BY_GOD FINANCIAL  PCRQ self_relig_index parent_relig_index ///
wb_today thriving happy life_sat ///
mental_health  physical_hlth life_purpose ///
promote_good give_up sat_relatnshp   ///
depressed	suffering	interest	bodily_pain ///
god_punish1 loved_by_god1 comfort_rel1 ///
live_alone REincome_feelings covid_death unemployed REhealth_growup married was_abuse  [aw=weight]

pwcorr HOPE HAPPY ACCEPTED_BY_GOD FINANCIAL  , st(.01)    sig

candisc HOPE HAPPY ACCEPTED_BY_GOD FINANCIAL  , group(country)

pwcorr HOPE HAPPY ACCEPTED_BY_GOD FINANCIAL  PCRQ self_relig_index parent_relig_index ///
days_exercise drinks donated [aw=weight]

global f1 "hope_future	content	grateful	promote_good	worthwhile	sat_relatnshp	expect_good	wb_fiveyrs	show_love	life_purpose	happy	freedom	give_up	life_sat	people_help	wb_today	mental_health	physical_hlth	belonging"
global f2 "feel_anxious	control_worry	depressed	suffering	interest	bodily_pain	threat_life" 
global f3 "comfort_rel1	life_approach1	loved_by_god1	critical1	god_punish1"
global f4 "expenses worry_safety REincome_feelings"

**Reference/*
Rönkkö, M., & Cho, E. (2022). An updated guideline for assessing discriminant validity. Organizational Research Methods, 25(1), 6-14.
*/

**Recommended methods from Rönkkö & Cho, adapting their code. 
////////// Baseline model ////////// 

sem (HOPE -> $f1) ///
	(HAPPY -> $f2) ///
	(ACCEPTED_BY_GOD -> $f3) ///
	(FINANCIAL-> $f4), ///
	variance (HOPE@1 HAPPY@1 ACCEPTED_BY_GOD@1 FINANCIAL@1)  nocapslatent 
estimates store m1

////////// Techniques using model fit indices: comparison //////////
////////// against model with correlation fixed at cutoff //////////

egen WELL=rowmean($f1 $f2)

sem (WELL -> $f1 $f2) ///
    (ACCEPTED_BY_GOD -> $f3) ///
	(FINANCIAL-> $f4), ///
	variance (WELL@1  ACCEPTED_BY_GOD@1 FINANCIAL@1)  nocapslatent 
	
estimates store m2
lrtest m1 m2, dir stat

*766,003.48
*-7053670.2 
////////// Techniques using model fit indices: comparison //////////
////////// test against model with correlation fixed at cutoff //////////

sem (HOPE -> $f1) ///
	(HAPPY -> $f2) ///
	(ACCEPTED_BY_GOD -> $f3) ///
	(FINANCIAL-> $f4), ///
	variance (HOPE@1 HAPPY@1 ACCEPTED_BY_GOD@1 FINANCIAL@1)  nocapslatent ///
	covariance(HOPE*HAPPY@.96)
*679,997.40  
*-7010667.2  
estimates store m3

lrtest m1 m3, dir stat

////////// Techniques using model fit indices: comparison //////////
////////// TEST single dominant latent construct vs baseline //////////

egen WELL2=rowmean($f1 $f2 $f3 $f4)

sem (WELL2 -> $f1 $f2 $f3 $f4), ///
	variance (WELL2@1)  nocapslatent 
	
estimates store m4
lrtest m1 m4, dir stat
